Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this PR, the REST calls to external services would be performed twice:
flatMap
from each step to get the nextMono.zip
on all those stepsAs a general point, applications should avoid as much as possible chaining calls to external services as latency and issues tend to accumulate. If you can't get around this by caching or parallelizing calls, you could still consider other ways. This sample is very generic so I can't really advise something specific. But let's say one of those steps is about getting information from the HTTP header and checking credentials: you could externalize that cross-cutting concern into a
WebFilter
.This PR is trying to simplify things and come up with a single reactive pipeline in the controller (i.e. a single input, and chaining calls with operators, returning the result). For that, we need to use Reactor's
Tuples
(or anything similar like apache commons, Vavr or others). Depending on the use case, we could come up with a better model design but it doesn't require specific reactive skills.I'm getting the expected value and no duplicate logs when calling the service with httpie:
With sequential, external calls, the reactive approach could help in several ways:
WebClient
instance instead of creating a new one for each call.timeout
/retry
and other related operators to improve the service behavior here